<template>
  <div class="top">
    <div class="content">
      <!-- 左侧 -->
      <div class="left" @click="goHome">
        <div>
          <!-- <img src="@/assets/images/logo.png" alt=""/> -->
          <el-avatar shape="square" :src="userStore.userInfo.avatar" />
        </div>
        <div>
          <p>深圳市友商信息技术科技有限公司</p>
        </div>
      </div>
      <div class="right">
        <div style="margin-left: 4px">
          <el-button type="default" icon="Search" circle />
        </div>
        <div style="margin-left: 4px">
          <el-button type="default" icon="FullScreen" circle />
        </div>
        <div style="margin-left: 4px">
          <el-button type="default" icon="Menu" circle />
        </div>
        <div style="display: flex">
          <div style="margin-left: 4px" v-if="!userStore.userInfo.name">
            <el-button type="default" icon="UserFilled" @click="login">Sign in</el-button>
          </div>
          <div style="margin-left: 4px" v-if="userStore.userInfo.name">
            <el-avatar shape="square" :size="32" :src="userStore.userInfo.avatar2" />
          </div>
          <div style="margin-left: 4px" v-if="userStore.userInfo.name">
            <el-dropdown split-button type="default">
              <span>{{ userStore.userInfo.name }}</span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item @click="goUser('/user/certification')">实名认证</el-dropdown-item>
                  <el-dropdown-item @click="goUser('/user/order')">挂号订单</el-dropdown-item>
                  <el-dropdown-item @click="goUser('/user/patient')">就诊人管理</el-dropdown-item>
                  <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
//引入路由器
import {useRouter} from "vue-router";
//获取user仓库的数据( visiable)可以控制login组件的对话框显示与隐藏
import useUserStore from "@/store/modules/user";

let userStore = useUserStore();

let $router = useRouter();
const goHome = () => {
  //编程式导航跳转到首页
  $router.push({path: "/home"});
};
//点击登录与注册按钮的时候弹出对话框
const login = () => {
  userStore.visiable = true;
};
//退出登录按钮的回调
const logout = () => {
  //通知pinia仓库清除用户相关的信息
  userStore.logout();
  //编程式导航路由跳转到首页
  $router.push({path: "/home"});
};

//点击顶部下拉菜单进行路由跳转
const goUser = (path: string) => {
  $router.push({path: path});
};
</script>

<style scoped lang="scss">
.top {
  position: fixed;
  z-index: 999;
  width: 100%;
  height: 70px;
  background-color: #f4f4f4;

  display: flex;
  justify-content: center;

  .content {
    width: 1200px;
    height: 70px;
    background: linear-gradient(to right, rgb(190, 190, 190), white);
    display: flex;
    justify-content: space-between;

    .left {
      display: flex;
      justify-content: center;
      align-items: center;

      img {
        width: 70px;
        height: 70px;
        margin-right: 8px;
      }

      .el-avatar {
        width: 70px;
        height: 70px;
        margin-right: 8px;
      }

      p {
        font-size: 20px;
        color: #55a6fe;
      }
    }

    .right {
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 14px;
      color: #333333;

      .help {
        margin-right: 10px;
      }
    }
  }
}
</style>
